package com.hnust.dao;

import com.hnust.domain.CollegeAdmin;
import com.hnust.domain.record.CollegeAdminRecord;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 *创建人：张汝往、王月阳
 *创建时间：2020/10/6
 *描述：
 */
@Mapper
@Repository
public interface CollegeAdminDao {

    //根据账号密码查询院管理员
    @Select("select * from college_admin where account=#{account} and password=#{password}")
    @ResultType(CollegeAdmin.class)
    CollegeAdmin findCollegeAdmin(String account, String password);

    //根据管理员ID查询院管理员
    @Select("select * from college_admin where col_adm_id=#{adminId}")
    @ResultType(CollegeAdmin.class)
    CollegeAdmin findCollegeAdminByAdminId(String adminId);

    //根据院管理员Id更新密码
    @Update("update college_admin set password=#{newPassword} where col_adm_id=#{adminId}")
    @ResultType(Boolean.class)
    Boolean updatePasswordByAdminID(String adminId,String newPassword);

    //校管理员-院管理员设置
    //添加院管理员
    @Insert("insert into college_admin(col_adm_id,account,password,name,col_id) values (#{collegeAdmin},#{account},#{password},#{name},#{collegeId})")
    @ResultType(Boolean.class)
    Boolean addCollegeAdmin(String collegeAdmin, String account, String password, String name, String collegeId);

    //校管理员获取院管理员列表
    @Select("select college_admin.account,college_admin.password,college_admin.col_adm_id as collegeAdminId,college_admin.name,college.col_id as collegeId,college.name as college from college,college_admin where college.col_id=college_admin.col_id")
    @ResultType(CollegeAdminRecord.class)
    List<CollegeAdminRecord> getCollegeAdmin();

    //校管理员删除院管理员
    @Delete("delete from college_admin where col_adm_id = #{collegeAdminId}")
    @ResultType(Boolean.class)
    Boolean deleteCollegeAdmin(String collegeAdminId);

    //校管理员批量删除院管理员
    @Delete("delete from college_admin where col_adm_id IN (${collegeAdminIds})")
    @ResultType(Integer.class)
    int batchDeleteCollegeAdmin(String collegeAdminIds);

    //根据管理员ID查询院管理员
    @Select("select col_id from college_admin where account=#{account}")
    @ResultType(String.class)
    String getCollegeIdByAdminAccount(String account);

    //校管理员编辑院管理员
    @Update("update college_admin set name = #{name},account = #{account},password = #{password},col_id = #{collegeId} where col_adm_id = #{collegeAdminId}")
    @ResultType(Boolean.class)
    Boolean modifyCollegeAdmin(String name,String account,String password,String collegeAdminId,String collegeId);
}
